package com.community.config;

import java.util.Properties;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class MyWebAppConfiguration extends WebMvcConfigurerAdapter {
    /**
     * Spring Boot中有默认的静态资源访问路径，浏览器也不允许访问项目目录外的资源文件
     * 添加一些虚拟路径的映射
     * 设置静态资源路径和上传文件的路径
     */
     @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // /** 表示该目录下所有文件
   
        
 
		
		
		Properties pop = System.getProperties(); // 获取当前的系统属性集
		System.out.println(pop.getProperty("os.name")); // 操作系统的版本
		if (pop.getProperty("os.name").contains("Windows")) {
		     registry.addResourceHandler("/ueditor/image/**").addResourceLocations("file:/d:/community/ueditor/upload/image/");
		        registry.addResourceHandler("/image/**").addResourceLocations("file:/d:/community/ueditor/upload/image/");
		        registry.addResourceHandler("/discuss/detail/image/**").addResourceLocations("file:/d:/community/ueditor/upload/image/");
		        
		       
		        registry.addResourceHandler("/ueditor/file/**").addResourceLocations("file:/d:/community/ueditor/upload/file/");
		        registry.addResourceHandler("/user/header/**").addResourceLocations("file:/d:/community/ueditor/upload/file/");
		} else {

		     registry.addResourceHandler("/ueditor/image/**").addResourceLocations("file:/opt/community/ueditor/upload/image/");
		        registry.addResourceHandler("/image/**").addResourceLocations("file:/opt/community/ueditor/upload/image/");
		        registry.addResourceHandler("/discuss/detail/image/**").addResourceLocations("file:/opt/community/ueditor/upload/image/");
		        
//		        /community/discuss/detail/image
		        registry.addResourceHandler("/ueditor/file/**").addResourceLocations("file:/opt/community/ueditor/upload/file/");
		        registry.addResourceHandler("/user/header/**").addResourceLocations("file:/opt/community/ueditor/upload/file/");
		
			
		}
		
		
		
        
        super.addResourceHandlers(registry);
    } 
}